<template>
  <div class="app-main-content">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.deviceCode" placeholder="设备编号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        prop="deviceCode"
        label="设备编号"
        >
      </el-table-column>
      <el-table-column
        prop="oprType"
        label="操作类型"
        >
      </el-table-column>
      <el-table-column
        prop="oprator"
        label="操作人"
        >
      </el-table-column>
      <el-table-column
        prop="oprTm"
        label="操作时间"
        >
      </el-table-column>
      <el-table-column
        prop="cmdSrc"
        label="操作平台"
        >
      </el-table-column>
      <el-table-column
        prop="lockStatus"
        label="锁状态"
        >
      </el-table-column>
      <el-table-column
        prop="result"
        label="操作结果"
        >
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        label="操作">
        <template slot-scope="scope">
          <el-button @click="showAlarmLoc(scope.row)"  v-if="scope.row.lng>0" type="text">查看位置</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <map-dialog v-if="dialogVisible" ref="mapDialog" :childComp="'showRoads'" :data-source="datas"  :title="'查看开锁位置'">
      <show-loc :data-source="datas"></show-loc>
    </map-dialog>
  </div>
</template>

<script>
  import * as $http from '@/api/deviceoprlog'
  import mapDialog from './map-dialog'
  import showLoc from './show-loc'
  export default {
    data() {
      return {
        dataForm: {
          deviceCode: ''
        },
        datas:{},
        dialogVisible:false,
        map:null,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      mapDialog,
      showLoc
    },
    mounted: function () {
      this.getDataList()
    },
    methods: {
      //查看报警位置
      showAlarmLoc(row){
        this.datas = {lat:row.lat,lng:row.lng};
        if(this.$refs['mapDialog'] && this.$refs['mapDialog'].showMap)
          this.$refs['mapDialog'].showMap();
        else
        if(!this.dialogVisible)
          this.dialogVisible = true;
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        let rules = []
        rules.push({"field": "device_code", "op": "cn", "data": this.dataForm.deviceCode.trim()})
        let filters = {"groupOp": "AND", "rules": rules}
        let params = {
          filters: filters, // 围栏号
          page: this.pageIndex, // 当前页索引
          limit: this.pageSize // 每页大小
        }
        $http.list(params).then(data => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },


    }
  }
</script>
